package com.aster.service.manage.service.impl;

import com.aster.common.base.BaseServiceImpl;
import com.aster.common.dto.UserToken;
import com.aster.common.exception.ServiceException;
import com.aster.common.utils.PageUtils;
import com.aster.service.manage.dao.LabelInfoDao;
import com.aster.service.manage.domain.TbHospitalInfo;
import com.aster.service.manage.domain.TbLabelInfo;
import com.aster.service.manage.dto.DtoHospitalInfo;
import com.aster.service.manage.dto.DtoLabelInfo;
import com.aster.service.manage.dto.do2dto.HospitalInfoConvert;
import com.aster.service.manage.dto.do2dto.LabelInfoConvert;
import com.aster.service.manage.service.LabelInfoService;
import com.aster.service.manage.service.criteria.LabelInfoCriteria;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 
 * <br>
 * <b>功能：</b>TbLabelInfoService<br>
 */
@Service("labelInfoService")
public class  LabelInfoServiceImpl  extends BaseServiceImpl implements LabelInfoService {
  private final static Logger log= Logger.getLogger(LabelInfoServiceImpl.class);
	

	@Autowired
    private LabelInfoDao dao;

		
	public LabelInfoDao getDao() {
		return dao;
	}


	@Override
	public PageUtils getLabelInfoForPage(LabelInfoCriteria criteria) {
		Integer count = dao.queryByCount(criteria);
		if(count == null || count == 0){
			return new PageUtils(null,0);
		}
		List<TbLabelInfo> list = dao.queryByList(criteria);
		List<DtoLabelInfo> dtoList = LabelInfoConvert.MAPPER.dos2dtos(list);
		return new PageUtils(dtoList,count);
	}

	@Override
	public void addLabelInfo(TbLabelInfo tbLabelInfo, UserToken userToken) throws ServiceException {
		if (tbLabelInfo == null){
			throw new ServiceException(10001,"参数为空");
		}
		try {
			tbLabelInfo.setEnterpriseId(userToken.getEnterpriseId());
			tbLabelInfo.setCreateTime(new Date());
			tbLabelInfo.setUpdateTime(new Date());
			tbLabelInfo.setCreateUserId(Integer.parseInt(userToken.getUserId()));
			tbLabelInfo.setUpdateUserId(Integer.parseInt(userToken.getUserId()));
			tbLabelInfo.setState(0);
			tbLabelInfo.setDeleted(1);
			dao.add(tbLabelInfo);
		}catch (Exception ex){
			throw new ServiceException(10000,ex.getMessage());
		}
	}

	@Override
	public void editLabelInfo(TbLabelInfo tbLabelInfo, UserToken userToken) throws ServiceException {
		if (tbLabelInfo == null){
			throw new ServiceException(10001,"参数为空");
		}
		try{
			tbLabelInfo.setUpdateUserId(Integer.parseInt(userToken.getUserId()));
			tbLabelInfo.setUpdateTime(new Date());
			dao.updateBySelective(tbLabelInfo);
		}catch (Exception ex){
			ex.printStackTrace();
			throw new ServiceException(10000,ex.getMessage());
		}
	}

	@Override
	public TbLabelInfo selectByOne(Object id) {
		return dao.selectByOne(id);
	}
}
